package org.zerta.troops.client;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.zerta.troops.common.TurnData;
import org.zerta.troops.common.World;
import org.zerta.troops.network.TroopsNetworkClient;

public class GameController implements ActionListener {

	// Model
	private World world;
	
	// Network
	private TroopsNetworkClient troopsNetworkClient;

	// State variables
    private String highlightedAreaName;
    private String draggingAreaName;

	// TODO: Add more actions here, with public getters to allow triggering and listening.
	//private UpdateAction updateAction;
	
	public GameController(World w, TroopsNetworkClient c) {
		// Our dear Model (Maybe we should just construct the world in here?)
		world = w;
		
		// Network client for sending stuff to server
		troopsNetworkClient = c;

		// State variables
		highlightedAreaName = "";
		draggingAreaName = "";

		// Actions that can be triggered by external independent GUI code
		//updateAction = new UpdateAction();
	}

	public World getWorld() {
		return world;
	}

    /**
     * Set currently highlighted area.
     * @param name
     */
    public void setHighlightedArea(String name) {
        highlightedAreaName = name;
        // TODO: Trigger update in GUI!
        //repaint();
        //repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);
    }

    public String getHighlightedArea() {
        return highlightedAreaName;
    }

    /**
     * Set currently dragged area.
     * @param name
     */
    public void setDraggingArea(String name) {
    	draggingAreaName = name;
        // TODO: Trigger update in GUI!
        //repaint();
        //repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);
    }

    public String getDraggingArea() {
    	return draggingAreaName;
    }
	
	public void endTurn() {
		// TODO Send turn data to server here
		troopsNetworkClient.sendTurnData(new TurnData());
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub		
	}
}
